package everyday;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @ClassName D720
 * @Description https://leetcode-cn.com/problems/continuous-median-lcci/
 * @Author Yin
 * @Date 2021/4/2 13:41
 * @Version 1.0
 */
public class D720 {
    List<Integer> ans = new ArrayList<>();

    public D720() {

    }

    public void addNum(int num) {
        ans.add(num);
    }

    public double findMedian() {
        ans.sort(Comparator.comparingInt(o -> o));
        int size = ans.size();
        int m  =size/2;
        if (size % 2 == 1) {
            return 1.0*ans.get(m);
        }else{
            return 1.0*(ans.get(m-1)+ans.get(m))/2;
        }
    }
}
